在小米路由器3G的OpenWRT环境安装node.js

您所在的位置:网站首页 openwrt jd 在小米路由器3G的OpenWRT环境安装node.js

在小米路由器3G的OpenWRT环境安装node.js

#在小米路由器3G的OpenWRT环境安装node.js| 来源: 网络整理| 查看: 265

(一)node.js 安装要求

在路由器的 OpenWRT 环境安装 node.js 环境需要有以下几个条件:

Flash 和内存要相对较大。我编译的 Node.js 和 npm 分别为6兆字节和4.5兆字节,因此需要选择硬件资源比较富裕的一些硬件。比如:小米路由器3G,带 USB 接口的 V1 版本,内存和 Flash 有256MB/128MB。 ning@bdcloud:node$ ll total 10304 drwxr-xr-x 2 ning ning 4096 Jan 5 16:02 ./ drwxr-xr-x 8 ning ning 4096 Jan 5 15:49 ../ -rw-r--r-- 1 ning ning 6028619 Jan 5 15:50 node-npm_v8.17.0-1_mipsel_24kc.ipk -rw-r--r-- 1 ning ning 4493900 Jan 5 15:49 node_v8.17.0-1_mipsel_24kc.ipk 如何将小米路由器刷上OpenWRT固件,可以参考我的一些博客文章: DIY: 基于OpenWRT和小米路由器的透明代理(SSR) DIY: 基于OpenWRT和小米路由器的透明代理(SSR)(后记) 有关小米路由器3G刷OpenWRT固件的几个常见问题 硬件如果有浮点处理单元 FPU,比如树莓派 Raspberry-Pi,则通过 opkg install node的方法就可以直接安装了。 如果硬件不支持(大多数嵌入式CPU都不支持),则需要自己编译内核和软件,让软件来模拟浮点处理单元FPU。 (二)node.js 的 OpenWRT版本的编译过程

Hirokazu MORIKAWA的github项目 https://github.com/nxhack/openwrt-node-packages 是支持arm/mips/x86架构的,能够满足大多数的嵌入式设备。下面是我的编译过程:

使用 OpenWRT的 V18.06.5分支编译 git clone https://github.com/openwrt/openwrt git checkout v18.06.5 将 openwrt-node-packages 项目添加到 openwrt 项目中 在 feeds.conf.default 文件中最后一行添加,并指定使用该项目的 openwrt-18.06 分支 src-git node https://github.com/nxhack/openwrt-node-packages.git;openwrt-18.06 运行如下命令: ./scripts/feeds update node rm ./package/feeds/packages/node rm ./package/feeds/packages/node-* ./scripts/feeds install -a -p node 编译配置: make menuconfig 选择小米路由器3G,带 USB 接口的 V1 版本 Target System (MediaTek Ralink MIPS) ---> Subtarget (MT7621 based boards) ---> Target Profile (Xiaomi Mi Router 3G) ---> 选择 FPU 模拟器 Global build settings ---> Kernel build options ---> [*] Compile the kernel with MIPS FPU Emulator 选择v8 版本的 node.js 和 npm Languages ---> Node.js ---> -*- node.......... Node.js is a platform built on Chrome's JavaScript runtime Configuration ---> Version Selection (8.x Maintenance LTS) Languages ---> Node.js ---> node-npm............................. NPM stands for Node Package Manager 编译 make V=99 编译后的OpenWRT固件位置在 openwrt/bin/targets/ramips/mt7621/openwrt-ramips-mt7621-mir3g-squashfs-sysupgrade.tar node.js 和 npm 安装文件在 openwrt/bin/packages/mipsel_24kc/node/node_v8.17.0-1_mipsel_24kc.ipk openwrt/bin/packages/mipsel_24kc/node/node-npm_v8.17.0-1_mipsel_24kc.ipk (三)node.js 和 npm 的安装 将 node_v8.17.0-1_mipsel_24kc.ipk 和 node-npm_v8.17.0-1_mipsel_24kc.ipk 通过 sftp 上传到单板上。通过 opkg 命令进行安装 opkg install node_v8.17.0-1_mipsel_24kc.ipk opkg install node-npm_v8.17.0-1_mipsel_24kc.ipk

至此,任务达成。如果觉得编译太麻烦,可以直接使用我编译的版本。(注意:只能在小米路由器3G上使用)。 https://chou-o-ning.github.io/blog/assets/node_v8.17.0-1_mipsel_24kc.ipk https://chou-o-ning.github.io/blog/assets/node-npm_v8.17.0-1_mipsel_24kc.ipk https://chou-o-ning.github.io/blog/assets/openwrt-ramips-mt7621-mir3g-squashfs-sysupgrade.tar

(四)安装中出现的一些情况 在使用 npm install 命令时会出现下面的一些错误,但不影响使用,可以忽略之。 npm ERR! code ENOENT npm ERR! syscall scandir npm ERR! path /tmp/npm-5228-90177edd npm ERR! errno -2 npm ERR! enoent ENOENT: no such file or directory, scandir '/tmp/npm-5228-90177edd' npm ERR! enoent This is related to npm not being able to find a file. npm ERR! enoent npm ERR! code ENOENT npm ERR! syscall scandir npm ERR! path /tmp/npm-5228-90177edd npm ERR! errno -2 npm ERR! enoent ENOENT: no such file or directory, scandir '/tmp/npm-5228-90177edd' npm ERR! enoent This is related to npm not being able to find a file. npm ERR! enoent node是单独编译的,因此 opkg update 的时候会出现错误,可以不用理会。 opkg update Downloading http://downloads.openwrt.org/releases/18.06.5/packages/mipsel_24kc/node/Packages.gz *** Failed to download the package list from http://downloads.openwrt.org/releases/18.06.5/packages/mipsel_24kc/node/Packages.gz 由于使用的是编译的内核,因此在安装一些模块时会出现下面的错误: root@OpenWrt:~# opkg install luci-app-shadowsocksR-GFW_1.2.1_all.ipk Installing luci-app-shadowsocksR-GFW (1.2.1) to root... Collected errors: * satisfy_dependencies_for: Cannot satisfy the following dependencies for luci-app-shadowsocksR-GFW: * kernel (= 4.14.151-1-16b77c6fbb9d9192d39ab642ba67d11a) * opkg_install_cmd: Cannot install package luci-app-shadowsocksR-GFW.

可以使用下面的命令,看到相关的依赖模块。

root@OpenWrt:~# rm -fr /var/opkg-lists/ root@OpenWrt:~# opkg install luci-app-shadowsocksR-GFW_1.2.1_all.ipk Installing luci-app-shadowsocksR-GFW (1.2.1) to root... Collected errors: * satisfy_dependencies_for: Cannot satisfy the following dependencies for luci-app-shadowsocksR-GFW: * ipset * ip * iptables-mod-tproxy * libpcre * dnsmasq-full * coreutils * coreutils-base64 * opkg_install_cmd: Cannot install package luci-app-shadowsocksR-GFW.

依赖模块中,有些模块是用户态程序,比如 coreutils,不依赖于内核,可以通过 opkg update 和 opkg install 命令一个一个安装。

opkg update opkg install coreutils

有些模块是内核模块,比如 ipset,这时就必须要使用自己编译出来的模块了。使用下面的命令找到相关的模块:

ning@bdcloud:openwrt$ find . -name ipset*.ipk ./bin/packages/mipsel_24kc/base/ipset_6.38-1_mipsel_24kc.ipk ./staging_dir/packages/ramips/ipset_6.38-1_mipsel_24kc.ipk

然后上传到单板上,单独安装指定文件。

root@OpenWrt:~# opkg install ipset_6.38-1_mipsel_24kc.ipk

如果还继续出现依赖性错误,则继续下面的操作:

rm -fr /var/opkg-lists/ root@OpenWrt:~# opkg install ipset_6.38-1_mipsel_24kc.ipk

打印出依赖关系后,继续递归处理每个安装文件。



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3